package com.ocean.controller.library;

import com.ocean.entity.library.Book;
import com.ocean.entity.library.Category;
import com.ocean.entity.library.Library;
import com.ocean.service.library.BookService;
import com.ocean.service.library.CategoryService;
import com.ocean.service.library.LibraryService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Project：SchoolManage
 * Package：com.ocean.controller.library
 * Author:zy
 * Time:2023/3/3
 */
@RestController
@RequestMapping("/api/library/book")
public class BookController {
    @Autowired//--
    private BookService bookService;
    @Autowired
    private LibraryService libraryService;
    @Autowired
    private CategoryService categoryService;

    @PostMapping("save.do")
    public R save(@RequestBody Book book){
        return bookService.save(book);
    }

    @RequestMapping("querypage.do")
    public R queryPage(int page, int size,String name,String author){

        return bookService.queryPage(page,size,name,author);
    }

    @GetMapping("del.do")
    public R queryPage(int id){

        return bookService.delete(id);
    }

    @GetMapping("selectlib.do")
    public R querylib(){
        List<String> ls = (List)libraryService.queryAll().getData();
        return R.ok(ls);
    }
    @GetMapping("selectcag.do")
    public R querycag(){
        List<String> cs = (List)categoryService.queryAll().getData();
        return R.ok(cs);
    }

    @PostMapping("update.do")
    public R update(@RequestBody Book book){

        return bookService.update(book);
    }

    @GetMapping("selectIdByName.do")
    public R selectIdByName(String name){
        return bookService.selectIdByName(name);
    }

    @PostMapping("import.do")
    public R importexcel(MultipartFile file) throws IOException {

        return bookService.importData(file);
    }

    @GetMapping("export.do")
    public void exportexcel(HttpServletResponse response) throws IOException {

        bookService.exportData(response);
    }

    @GetMapping("echarts.do")
    public R echarts() throws IOException {

        return bookService.queryEcharts();
    }

    

}
